#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+10;
struct node
{
	int x;//开始
	int y;//结束
}nums[N];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>nums[i].x>>nums[i].y;
	}
	sort(nums+1,nums+1+n,[](const node&a,const node&b)
		{
			return a.x<b.x;
		});

	int r=nums[1].y;
	int ret=1;
	for(int i=2;i<=n;i++)
	{
		int left=nums[i].x;
		int right=nums[i].y;
		if(r<=left)
		{
			ret++;
			r=right;
		}
		r=min(r,right);
	}
	cout<<ret<<endl;
}